from bs4 import BeautifulSoup
import csv, os
os.chdir("D:\\KIPRIS\\Biblio")

# csv file and csv object
f = open("PCT.csv", "a", encoding="utf-8", newline="")
wf = csv.writer(f)

for year in range(1984, 1999):
	directory = "D:\\KIPRIS\\Biblio\\PCT{}.xml".format(year)
	file = open(directory, "r", encoding= "utf-8")
	txt = file.read()
	txt = txt.replace("\n", "")
	xml_list = txt.split('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>')
	for xml in xml_list[1:]:
		biblio = BeautifulSoup(xml, 'xml')
		anum = biblio.find("applicationNumber").text
		adate = biblio.find("applicationDate").text
		onum = biblio.find("openNumber").text
		odate = biblio.find("openDate").text
		rnum = biblio.find("registerNumber").text
		rdate = biblio.find("registerDate").text
		line = [anum, adate, onum, odate, rnum, rdate]
		wf.writerow(line)
		print(line)